﻿using Authentication.Model.Interface;
using Authentication.Model.Model;
using Common.Contract;
using Common.Contract.Authentication;
using Common.Contract.Authentication.Identifier;
using Common.Contract.Authentication.Request;
using Common.Service.Command;
using Common.Util;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Authentication.ServiceCommand
{
    public class DeleteObjectServiceCommand : ProviderServiceCommand<IObjectProvider, DeleteObjectRequest, ResponseRecord>
    {
        public DeleteObjectServiceCommand(IObjectProvider providers) : base(providers) { }
        protected override void Validate(DeleteObjectRequest request)
        {
            if (request == null) throw new ArgumentNullException("request");
            if (!request.Header.ApplicationKey.HasValue || request.Header.ApplicationKey == Guid.Empty)
            {
                throw new ArgumentException("ApplicationKey must be set", "request");
            }
            if (request.Record == null)
            {
                throw new ArgumentException("Record must be set", "request");
            }
            //if (!RoleIdentifier.IsValid(request.Record))
            //{
            //    throw new ArgumentException("RoleIdentifier is invalidate", "request");
            //}
        }

        protected override bool OnExecute(ResponseRecord response)
        {
            var applicationKey = Request.Header.ApplicationKey.Value;
            var roleId = Providers.Delete(applicationKey, Request.Record);
            return roleId;
        }
    }
}
